<?php
require_once 'Zend/Controller/Action.php';

class AdmAreaController extends Zend_Controller_Action {
	
	
	//LoginPage
    public function indexAction() {

    }
    
    public function clientSelectFormAction() { 	
    }
    
    public function loginAction() {
    	 if (	$this->_getParam('username') != ''	) {
    	 	
		 	$username=$this->_getParam('username');
	    	$password=$this->_getParam('password');
				
			require_once 'Zend/Auth.php';	
			$auth = Zend_Auth::getInstance();
	
			//check for other adapters such as the pdo/...
			//will move from here anyway ;-)
			require_once 'Zend/Db/Adapter/Mysqli.php';
			try {
			
				$db = new Zend_Db_Adapter_Mysqli(array(
				    'host'     => 'localhost',
				    'username' => 'root',
				    'password' => 'password',
				    'dbname'   => 'test'
				));
				    
				$db->getConnection();
							
			} catch (Zend_Db_Adapter_Exception $e) {
				echo $e->getMessage(); 
				throw $e;
			} 
	
			//Set up the authentication adapter
			require_once 'Zend/Auth/Adapter/DbTable.php';
			$authAdapter = new Zend_Auth_Adapter_DbTable
					($db, 'login', 'login', 'pass');
			$authAdapter->setIdentity($username);
			$authAdapter->setCredential($password);	
			// Attempt authentication, saving the result
			$result = $auth->authenticate($authAdapter);
			
	   	}
    	 
    	$this->_redirect('/admarea');	
    	 
    	 
    }
    
    public function logoutAction() {
    	$auth = Zend_Auth::getInstance();
    	$auth->clearIdentity();
    	
    	header('Location: http://'.$_SERVER["SERVER_NAME"]);
    }
}

?>